const mongoose = require('./db')

const userSchema = new mongoose.Schema({
    username:String,
    password:String,
})


const cateSchema = new mongoose.Schema({
    name:String,
    img:String
})

const proSchema = new mongoose.Schema({
    name:String,  //商品名称
    price:Number, //商品价格
    img:String,  //商品图片
    time:String, //商品时间
    nid:Number,  //商品编号
    cate:{
        type:mongoose.Schema.Types.ObjectId,
        ref:'cate'
    },
    content:String,
    shop:{      //商品店铺

        type:Number,
        default:0
    },
    status:{      //商品状态  0:待付款  1: 已付款 2: 已提货
        type:Number,
        default:0
    },
    goods:{   // 商品是否是购物车  0:不是  1:是
        type:Number,
        default:0
    },
    num:Number, //商品数量
    kucun:Number, //商品库存
    isChecked:{
        type:Boolean,
        default:false
    }
})

const hisSchema=mongoose.Schema({
    name:String
})
const hisModel=mongoose.model('his',hisSchema)

const adminSchema = mongoose.Schema({
    phonenumber:String,
    password:String,
})
const adminModel = mongoose.model('admin',adminSchema)

//小区表
const communitySchema = new mongoose.Schema({
    name: String,
    remark: {
        type: String,
        default: ''
    },
    admin_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'admin'
    }
})
const communityModel = mongoose.model('community', communitySchema, 'community')



//住户表---------------------
const residentSchema = new mongoose.Schema({
    name: String,//姓名
    phoneNumber: String,//电话
    gender: String,//性别
    idNumber: String,//身份证号
    residentType: String,//住户类型
    community_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'community'
    },
    remark: {
        type: String,
        default: ''
    },
    unit_id: {//单元id
        type: mongoose.Schema.Types.ObjectId,
        ref: 'unit'
    },
    apartmentNumber: String,//门牌号
    avater: {//头像
        type: String,
        default: 'https://pic1.zhimg.com/50/v2-6afa72220d29f045c15217aa6b275808_720w.jpg?source=1940ef5c'
    },
    payId: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Property'
    }, // 物业ID
    member:{
        type:Boolean,
        default:false
    },
    jifen:{
        type:String,
        default:'0'
    },
    datetime:String
});
const residentModel = mongoose.model('resident', residentSchema)

const userModel = mongoose.model('user', userSchema)
const cateModel = mongoose.model('cate', cateSchema)
const proModel = mongoose.model('pro', proSchema)



module.exports = {
    userModel,
    cateModel,
    proModel,
    adminModel,
    residentModel,
    hisModel
}








